package
{
    import flash.geom.Point;
	
	import mx.core.UIComponent;

	public class ResizeStateBorder extends UIComponent
	{
		private var minirectw:Number=4;
		private var minirecth:Number=3;
		public function  ResizeStateBorder()
		{
			super();
		}
		override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
		{
			super.updateDisplayList(unscaledWidth, unscaledHeight);
			var borderThickness:int =getStyle("borderThickness");
			var borderColor:int =getStyle("borderColor");
			graphics.clear();
			graphics.lineStyle(borderThickness,borderColor,1);//1表示aplha;
			drawBorder(this.x, this.y, unscaledWidth, unscaledHeight);
			
			
		}
		private function drawBorder(x1:Number, y1:Number, width:Number, height:Number):void{
			drawLine(x1,y1,x1+width,y1,true);
			drawLine(x1+width,y1,x1+width,y1+height,false);
			drawLine(x1,y1+height,x1+width,y1+height,true);
			drawLine(x1,y1,x1,y1+height,false);
		}
		public function drawLine(x1:Number, y1:Number,x2:Number,y2:Number,ishorizon:Boolean):void
		{ 
			//--------------0---------------
			//此处我们在其中点加上一个[],然后在此处添加拖拽事件
			//we think 4*3 rectangle may be  just fit;
			//中点坐标
		
			var controlpt:Array =new Array();
			var squarew:Number= minirectw>minirecth?minirecth:minirectw;
			
			if(ishorizon)
			{
				
				
				var mid_x:Number =(x1+x2)/2;
				//横向的线的纵坐标不变
				
				controlpt.push(new Point(x1+squarew/2,y1-squarew/2));
				controlpt.push(new Point(x1+squarew/2,y1+squarew/2));
				controlpt.push(new Point(x1-squarew/2,y1+squarew/2));
				controlpt.push(new Point(x1-squarew/2,y1-squarew/2));
				controlpt.push(new Point(x1+squarew/2,y1-squarew/2));			
				controlpt.push(new Point(x1+squarew/2,y1));
				controlpt.push(new Point(mid_x-minirectw/2,y1));
				controlpt.push(new Point(mid_x-minirectw/2,y1+minirecth/2));
				controlpt.push(new Point(mid_x+minirectw/2,y1+minirecth/2));
				controlpt.push(new Point(mid_x+minirectw/2,y1-minirecth/2));
				controlpt.push(new Point(mid_x-minirectw/2,y1-minirecth/2));
				controlpt.push(new Point(mid_x-minirectw/2,y1+minirecth/2));
				controlpt.push(new Point(mid_x+minirectw/2,y1+minirecth/2));
				controlpt.push(new Point(mid_x+minirectw/2,y1));
				controlpt.push(new Point(x2-squarew/2,y2));
				controlpt.push(new Point(x2-squarew/2,y2-squarew/2));
				controlpt.push(new Point(x2+squarew/2,y2-squarew/2));
				controlpt.push(new Point(x2+squarew/2,y2+squarew/2));
				controlpt.push(new Point(x2-squarew/2,y2+squarew/2));
				controlpt.push(new Point(x2-squarew/2,y2));
			}
			else
			{
				var mid_y:Number=(y1+y2)/2;
				//横坐标不变
				controlpt.push(new Point(x1-squarew/2,y1+squarew/2));
				controlpt.push(new Point(x1-squarew/2,y1-squarew/2));
				controlpt.push(new Point(x1+squarew/2,y1-squarew/2));
				controlpt.push(new Point(x1+squarew/2,y1+squarew/2));
				controlpt.push(new Point(x1-squarew/2,y1+squarew/2));
				controlpt.push(new Point(x1,y1+squarew/2));
				
				controlpt.push(new Point(x1,mid_y-minirectw/2));
				controlpt.push(new Point(x1-minirecth/2,mid_y-minirectw/2));
				controlpt.push(new Point(x1-minirecth/2,mid_y+minirectw/2));
				controlpt.push(new Point(x1+minirecth/2,mid_y+minirectw/2));
				controlpt.push(new Point(x1+minirecth/2,mid_y-minirectw/2));
				controlpt.push(new Point(x1-minirecth/2,mid_y-minirectw/2));
				controlpt.push(new Point(x1-minirecth/2,mid_y+minirectw/2));
				controlpt.push(new Point(x2,mid_y+minirectw/2));
				controlpt.push(new Point(x2,y2-squarew/2));
				controlpt.push(new Point(x2-squarew/2,y2-squarew/2));
				controlpt.push(new Point(x2-squarew/2,y2+squarew/2));
				controlpt.push(new Point(x2+squarew/2,y2+squarew/2));
				controlpt.push(new Point(x2+squarew/2,y2-squarew/2));
				controlpt.push(new Point(x2,y2-squarew/2));
			}
			for(var i:int=0;i<controlpt.length-1;i++)
			{
				var pt1:Point =controlpt[i] as Point;
				var pt2:Point =controlpt[i+1] as Point;
				graphics.moveTo(pt1.x,pt1.y);
				graphics.lineTo(pt2.x,pt2.y);
			}
			
			
		}	
		
	}
}